package com.ant.storage.common;
import lombok.Data;

/**
 * 响应数据(结果)最外层对象
 */
@Data
public class ResultVo<T> {
    /** 状态码 */
    private Integer code = 200;
    /** 提示信息 */
    private String message;
    /** 响应数据 */
    private T data;
    public ResultVo(){}

    private ResultVo(String msg){
        this.message = message;
    }

    private ResultVo(T data){
        this.data = data;
    }

    private ResultVo(Integer code, String message){
        this.code = code;
        this.message = message;
    }
    private ResultVo(String message, T data){
        this.message = message;
        this.data = data;
    }
    private ResultVo(Integer code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public static <T> ResultVo success(String message, T data)
    {
        return new ResultVo(message,data);
    }
    public static <T> ResultVo success(T data){

        return new ResultVo(ResultCode.SUCCESS.getResultCode(),ResultCode.SUCCESS.getResultMsg(),data);
    }
    public static ResultVo success(String message){
        return new ResultVo(ResultCode.SUCCESS.getResultCode(),message,null);
    }
    public static <T> ResultVo success(Integer code,String message,T data){
        return new ResultVo(code,message,data);
    }
    public static ResultVo fail(ResultCode resultCode){
        return new ResultVo(resultCode.getResultCode(),resultCode.getResultMsg());
    }
    public static ResultVo fail(String message){

        return new ResultVo(201,message);
    }
//    public static ResultVo success(String message){
//        return  new ResultVo(ResultCode.SUCCESS.getResultCode(),message,null);
//    }


    public static ResultVo failure(ResultInfoInterface resultInfoInterface) {
        ResultVo result = new ResultVo();
        result.setCode(resultInfoInterface.getResultCode());
        result.setMessage(resultInfoInterface.getResultMsg());
        result.setData(null);
        return result;
    }

    public static ResultVo failure(Integer code, String message) {
        ResultVo result=new ResultVo();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public ResultVo(ResultInfoInterface infoInterface) {
        this.code = infoInterface.getResultCode();
        this.message = infoInterface.getResultMsg();
    }
}
